import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Modal } from 'antd'
import { TreeContent } from '../../../../widgets'
import { menuList } from '../../../../utils/api'


export default class extends Component {
    static propTypes = {
        seachParams: PropTypes.any,
        defaultCheckedKeys: PropTypes.array,
        onCancel: PropTypes.func.isRequired,
        onSubmit: PropTypes.func.isRequired
    }

    constructor(props) {
        super(props)
        this.state = {
            visible: true,
            checkedValues: []
        }
    }

    checkVal = (values) => {
        this.setState({
            checkedValues: values || []
        })
    }


    render = () => {
        const params = this.props.seachParams || {}
        const { onCancel, onSubmit } = this.props
        return (
            <Modal
                visible={true}
                width={800}
                title={'关联菜单'}
                okText="保存"
                onCancel={onCancel}
                onOk={() => onSubmit(this.state.checkedValues)}
            >
                <TreeContent defaultCheckedKeys={this.props.defaultCheckedKeys} url={menuList} params={params} checkValue={this.checkVal}/>
            </Modal>

        )
    }
}
